package com.wencai.bean;

/**
 * @author wangpan
 * @date 2023/5/9
 */
public class IndexStocks {
    private String date;
    private String indexName;
    private String order;
    private String indexIncrement;
    private String firstStockName;
    private String firstStockCode;
    private String firstStockIncrement;
    private String secondStockName;
    private String secondStockCode;
    private String secondStockIncrement;
    private String thirdStockName;
    private String thirdStockCode;
    private String thirdStockIncrement;

    public double getAverageIncrement() {
        double index = indexIncrement == null ? 0 : Double.valueOf(indexIncrement);
        return calculateAverage(firstStockIncrement, secondStockIncrement, thirdStockIncrement) + index;
    }

    public static double calculateAverage(String str1, String str2, String str3) {
        int count = 0;
        double sum = 0.0;
        if (str1 != null) {
            count++;
            sum += Double.parseDouble(str1);
        }
        if (str2 != null) {
            count++;
            sum += Double.parseDouble(str2);
        }
        if (str3 != null) {
            count++;
            sum += Double.parseDouble(str3);
        }
        if (count == 0) {
            return 0;
        }
        return sum / count;
    }

    public double getMaxIncrement() {
        if (firstStockIncrement == null) {
            return 0;
        }
        return Double.valueOf(firstStockIncrement);
    }

    public double getMinIncrement() {
        return getMin(firstStockIncrement, secondStockIncrement, thirdStockIncrement);
    }

    public Double getMin(String s1, String s2, String s3) {
        Double[] arr = new Double[3];
        int i = 0;
        for (String s : new String[]{s1, s2, s3}) {
            if (s != null) {
                try {
                    arr[i++] = Double.valueOf(s);
                } catch (NumberFormatException e) {
                    // 如果无法解析为浮点型数值，忽略该值
                }
            }
        }
        Double min = null;
        for (Double d : arr) {
            if (d != null && (min == null || Double.compare(d, min) < 0)) {
                min = d;
            }
        }
        return min;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

    public String getIndexIncrement() {
        return indexIncrement;
    }

    public void setIndexIncrement(String indexIncrement) {
        this.indexIncrement = indexIncrement;
    }

    public String getFirstStockName() {
        return firstStockName;
    }

    public void setFirstStockName(String firstStockName) {
        this.firstStockName = firstStockName;
    }

    public String getSecondStockName() {
        return secondStockName;
    }

    public void setSecondStockName(String secondStockName) {
        this.secondStockName = secondStockName;
    }

    public String getThirdStockName() {
        return thirdStockName;
    }

    public void setThirdStockName(String thirdStockName) {
        this.thirdStockName = thirdStockName;
    }

    public String getFirstStockIncrement() {
        return firstStockIncrement;
    }

    public void setFirstStockIncrement(String firstStockIncrement) {
        this.firstStockIncrement = firstStockIncrement;
    }

    public String getSecondStockIncrement() {
        return secondStockIncrement;
    }

    public void setSecondStockIncrement(String secondStockIncrement) {
        this.secondStockIncrement = secondStockIncrement;
    }

    public String getThirdStockIncrement() {
        return thirdStockIncrement;
    }

    public void setThirdStockIncrement(String thirdStockIncrement) {
        this.thirdStockIncrement = thirdStockIncrement;
    }


    public String getFirstStockCode() {
        return firstStockCode;
    }

    public void setFirstStockCode(String firstStockCode) {
        this.firstStockCode = firstStockCode;
    }

    public String getSecondStockCode() {
        return secondStockCode;
    }

    public void setSecondStockCode(String secondStockCode) {
        this.secondStockCode = secondStockCode;
    }

    public String getThirdStockCode() {
        return thirdStockCode;
    }

    public void setThirdStockCode(String thirdStockCode) {
        this.thirdStockCode = thirdStockCode;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("IndexStocks{");
        sb.append("date='").append(date).append('\'');
        sb.append(", indexName='").append(indexName).append('\'');
        sb.append(", order='").append(order).append('\'');
        sb.append(", indexIncrement='").append(indexIncrement).append('\'');
        sb.append(", firstStockName='").append(firstStockName).append('\'');
        sb.append(", firstStockCode='").append(firstStockCode).append('\'');
        sb.append(", firstStockIncrement='").append(firstStockIncrement).append('\'');
        sb.append(", secondStockName='").append(secondStockName).append('\'');
        sb.append(", secondStockCode='").append(secondStockCode).append('\'');
        sb.append(", secondStockIncrement='").append(secondStockIncrement).append('\'');
        sb.append(", thirdStockName='").append(thirdStockName).append('\'');
        sb.append(", thirdStockCode='").append(thirdStockCode).append('\'');
        sb.append(", thirdStockIncrement='").append(thirdStockIncrement).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
